<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;

/**
 * @property float $cost_price 原价
 * @property int $id
 * @property int $sales 销量
 * @property int $spec_id 套餐
 * @property string $content 商品详情
 * @property string $createtime
 * @property string $images 商品图片
 * @property string $name 商品名称
 * @property-read \app\model\GoodsSpec $spec
 * @property-read \app\model\UserCollect $user_collect
 * @property-read mixed $images_text
 * @mixin \think\Model
 */
class Goods extends Model
{
	protected $createTime = 'createtime';
	
	protected $append = [
		'images_text'
	];
	
	function getImagesTextAttr($value,$data)
	{
		$value = $value ?? ($data['images'] ?? '');
		return $value?explode(',', $value):[];
	}
	
	
	public function userCollect()
	{
		return $this->hasOne(UserCollect::class,'pro_id')->where(['type'=>1]);
	}
	
	function spec()
	{
		return $this->belongsTo(GoodsSpec::class,'spec_id');
	}
}
